Accessibility

Populating the ListBox

When looking at the data returned by Flash Remoting in the NetConnection Debugger, you may notice that Flash Remoting converted the query to a RecordSet object. A RecordSet is like an array of objects. Below, you will use the data in the RecordSet to populate the ListBox. You can loop over the RecordSet to display the name property of an object, but Macromedia Flash improves this process with DataGlue.

DataGlue binds RecordSets to Macromedia Flash UI components. To use DataGlue, you'll include the DataGlue.as file.

Like HTML text areas, the ListBox lets you couple a piece of data for display to the users (called the label portion) with another piece of data that is associated with the selection (called the data portion). The ListBox goes improves upon this because the data associated with the selection can actually be an object. When you receive information about the user's selection from the ListBox, it can look like the following:

label Airstrike Design
data

If the ListBox has an instance name of parts_lb, you can get the description of the selected link by using the following syntax:

parts_lb.getSelectedItem().data.description

Using the bindFormatFunction() Method

Use the bindFormatFunction() method of DataGlue to determine the ListBox label and data elements. The general syntax is:

DataGlue.bindFormatFunction(dataConsumer,RecordSet,
	   formatFunction );

You must build a function to assign data to the label and data portions. In this tutorial, you want the label to equal the value of the name field returned from the database. Also, to make using the data as flexible as possible later, assign the entire object to the data portion. In the steps below, you will create a function like this:

this.binder=function(record){
	  var dataObj=new Object();
	  dataObj.label=record.name;
	  dataObj.data=record;
	  return dataObj;
	  }

The bindFormatFunction() automatically passes a record to the binder function, which assigns the label and data portions and then returns it to the function. By specifying the ListBox instance name as the dataConsumer, it will then display all the names in the ListBox.

Exercise 2

Exercise 2 shows you how to populate the ListBox.

  1. Open devnet.fla. (You can also use the file devnet_begin2.fla if you wish.)
  2. In the included ActionScript files section, include the file DataGlue.as file.
  3. Remove the trace statement from the partResponder.onResult method.
  4. In place partResponder.onResult, enter the bindFormatFunction() method with the following parameters:

    • dataConsumer: parts_lb
    • dataProvider: parts_rs
    • formatFunction: binder

    Note: Don't forget to use the ActionScript toolbox to select the function name.

  5. Ensure your responder method appears as shown here:

    partResponder.onResult=function(parts_rs){
    		DataGlue.bindFormatFunction(parts_lb,parts_rs,binder);
    	}
  6. In the functions section, create the skeleton of the function named binder, as follows:

    this.binder=function(record){
    	}
  7. In the function, perform the following:

    1. Create a variable local to the function named dataObj, which is a new object made from the Object class.
    2. Assign a label property of dataObj the name property of the record.
    3. Assign a data property of the dataObj the entire record.
    4. Return the dataObj.
  8. Ensure your function appears as shown here:
    this.binder=function(record){
    		var dataObj=new Object();
    		dataObj.label=record.name;
    		dataObj.data=record;
    		return dataObj;
    		}
  9. Save the document and test the movie. The ListBox now contains bicycle part names.

< Back | Contents | Next >

Submit feedback on our tutorials, articles, and sample applications.